#ifndef DATAMANAGER_H
#define DATAMANAGER_H

#include <QObject>
#include <QString>
#include <QDebug>

class DataManager : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)

public:
    explicit DataManager(QObject *parent = nullptr);

    const QString &name() const;
    void setName(const QString &newName);

    /**
     * @brief readName 读取名字
     * @return
     * 1. Q_INVOKABLE标记函数
     * 2. 返回的数据不能是引用类型，否则qml无法读取到undefined
     */
    Q_INVOKABLE QString readName() const {
        return m_name;
    }
signals:

    void nameChanged();

    /**
     * @brief dataSend 发送数据
     * @param name
     * @param val
     */
    void dataSend(const QString name, int val);

public slots:
    /**
     * @brief receiveQmlSignal 接收qml信号
     * @param data
     */
    void receiveQmlSignal(const QString &data) {
        qDebug() << "receiveQmlSignal: " <<data;

        emit dataSend(data + "1111", 233);
    }

private:
    QString m_name;
};

#endif // DATAMANAGER_H
